package jmine.tec.scheduling.pack;

import jmine.tec.database.pack.populator.AbstractPopulatorDataSource;
import jmine.tec.database.pack.populator.PopulatorBean;
import jmine.tec.scheduling.domain.ScheduledTask;
import jmine.tec.utils.collection.Mapper;
import jmine.tec.utils.collection.MapperUtils;
import bancosys.tec.persist.dao.BaseDAO;

/**
 * Populator data source for the scheduling pack.
 * 
 * @author ricardo.abe
 */
public class SchedulingPopulatorDataSource extends AbstractPopulatorDataSource<ScheduledTask> {

    private BaseDAO<ScheduledTask> scheduledTaskDAO;

    /**
     * {@inheritDoc}
     */
    public Iterable<PopulatorBean<ScheduledTask>> load() {
        return MapperUtils.mapList(this.scheduledTaskDAO.findAllOrderedByPk(), new Mapper<ScheduledTask, PopulatorBean<ScheduledTask>>() {
            public PopulatorBean<ScheduledTask> apply(ScheduledTask input) {
                return new PopulatorBean<ScheduledTask>(input, "scheduling", input.getMnemonic().toLowerCase() + ".xml");
            }
        });
    }

    /**
     * @param scheduledTaskDAO the scheduledTaskDAO to set
     */
    public void setScheduledTaskDAO(BaseDAO<ScheduledTask> scheduledTaskDAO) {
        this.scheduledTaskDAO = scheduledTaskDAO;
    }
}
